//
//  SISSSellRentNumPriceView.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/9/10.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSSellRentNumPriceView.h"
#import "SISSTitleView.h"

@interface SISSSellRentNumPriceView ()

/// titleView
@property (weak, nonatomic) SISSTitleView *titleView;
/// sellTitleLabel
@property (weak, nonatomic) UILabel *sellTitleLabel;
/// sellDirImgView
@property (weak, nonatomic) UIImageView *sellDirImgView;
/// sellNumAvgPriceLabel
@property (weak, nonatomic) UILabel *sellNumAvgPriceLabel;
/// sellMidLabel
@property (weak, nonatomic) UILabel *sellMidLabel;
/// sellAvgPriceLabel
@property (weak, nonatomic) UILabel *sellAvgPriceLabel;
/// midLineView
@property (weak, nonatomic) UIView *midLineView;
/// rentTitleLabel
@property (weak, nonatomic) UILabel *rentTitleLabel;
/// rentDirImgView
@property (weak, nonatomic) UIImageView *rentDirImgView;
/// rentNumAvgPriceLabel
@property (weak, nonatomic) UILabel *rentNumAvgPriceLabel;
/// rentMidLabel
@property (weak, nonatomic) UILabel *rentMidLabel;
/// rentAvgPriceLabel
@property (weak, nonatomic) UILabel *rentAvgPriceLabel;

@end
@implementation SISSSellRentNumPriceView


- (void)setSellNumAvgPrice:(NSString *)sellNumAvgPrice {
    _sellNumAvgPrice = sellNumAvgPrice;
    NSArray<NSString *> *arr = [sellNumAvgPrice componentsSeparatedByString:@"&&$$"];
    sellNumAvgPrice = [sellNumAvgPrice stringByReplacingOccurrencesOfString:@"&&$$" withString:@"套，均价："];
    NSMutableAttributedString *sellNumPriceAttri = [[NSMutableAttributedString alloc] initWithString:sellNumAvgPrice];
    [sellNumPriceAttri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, arr.firstObject.length)];
    [sellNumPriceAttri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(arr.firstObject.length + @"套，均价：".length, arr.lastObject.length)];
 
    self.sellNumAvgPriceLabel.attributedText = sellNumPriceAttri;
}

- (void)setRentNumAvgPrice:(NSString *)rentNumAvgPrice {
    _rentNumAvgPrice = rentNumAvgPrice;
    
    NSArray<NSString *> *arr = [rentNumAvgPrice componentsSeparatedByString:@"&&$$"];
    rentNumAvgPrice = [rentNumAvgPrice stringByReplacingOccurrencesOfString:@"&&$$" withString:@"套，均价："];
    NSMutableAttributedString *rentNumPriceAttri = [[NSMutableAttributedString alloc] initWithString:rentNumAvgPrice];
    [rentNumPriceAttri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, arr.firstObject.length)];
    [rentNumPriceAttri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(arr.firstObject.length + @"套，均价：".length, arr.lastObject.length)];
    
    self.rentNumAvgPriceLabel.attributedText = rentNumPriceAttri;
}

- (void)initUI {
    [super initUI];
    
    SISSTitleView *titleView = [[SISSTitleView alloc] init];
    titleView.titleStr = @"二手房";
    titleView.titleColor = MAIN_TEXT_COLOR;
    [self addSubview:titleView];
    self.titleView = titleView;
    
    UILabel *sellTitleLabel = [UILabel yyr_labelWithText:@"房屋出售" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self addSubview:sellTitleLabel];
    self.sellTitleLabel = sellTitleLabel;
    
    UIImageView *sellDirImgView = [[UIImageView alloc] init];
    sellDirImgView.image = [UIImage imageNamed:@"more"];
    [self addSubview:sellDirImgView];
    self.sellDirImgView = sellDirImgView;
    
    UILabel *sellNumAvgPriceLabel = [UILabel yyr_labelWithText:@"套，均价：" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self addSubview:sellNumAvgPriceLabel];
    self.sellNumAvgPriceLabel = sellNumAvgPriceLabel;
    
    UIView *midLineView = [[UIView alloc] init];
    midLineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addSubview:midLineView];
    self.midLineView = midLineView;
    
    UILabel *rentTitleLabel = [UILabel yyr_labelWithText:@"房屋出租" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self addSubview:rentTitleLabel];
    self.rentTitleLabel = rentTitleLabel;
    
    UIImageView *rentDirImgView = [[UIImageView alloc] init];
    rentDirImgView.image = [UIImage imageNamed:@"more"];
    [self addSubview:rentDirImgView];
    self.rentDirImgView = rentDirImgView;
    
    UILabel *rentNumAvgPriceLabel = [UILabel yyr_labelWithText:@"套，均价：" fontSize:15 textColor:MAIN_TEXT_COLOR];
    [self addSubview:rentNumAvgPriceLabel];
    self.rentNumAvgPriceLabel = rentNumAvgPriceLabel;
   
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(weakSelf);
        make.height.mas_equalTo(5.5 * margin);
    }];
    
    [self.sellTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleView.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf).multipliedBy(0.5);
    }];
    
    [self.sellDirImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.sellTitleLabel);
        make.left.equalTo(weakSelf.sellTitleLabel.mas_right).offset(0.5 * margin);
    }];
    
    [self.sellNumAvgPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.sellTitleLabel.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf.sellTitleLabel);
        make.bottom.equalTo(weakSelf).offset(-4 * margin);
    }];
    
    [self.midLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).offset(margin);
        make.centerX.equalTo(weakSelf);
        make.bottom.equalTo(weakSelf).offset(-2 * margin);
        make.width.mas_equalTo(1);
    }];
    
    [self.rentTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.sellTitleLabel);
        make.centerX.equalTo(weakSelf).multipliedBy(1.5);
    }];
    
    [self.rentDirImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.rentTitleLabel);
        make.left.equalTo(weakSelf.rentTitleLabel.mas_right).offset(0.5 * margin);
    }];
    
    [self.rentNumAvgPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.rentTitleLabel.mas_bottom).offset(2 * margin);
        make.centerX.equalTo(weakSelf.rentTitleLabel);
    }];
    
}

@end
